package com.ruoyi.statisticalCenter.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.statisticalCenter.domain.ScHqSysHqBillOne;
import com.ruoyi.statisticalCenter.domain.ScHqSysHqBillTwo;
import com.ruoyi.statisticalCenter.domain.vo.ScHqSysHqBillOneVo;
import com.ruoyi.statisticalCenter.domain.vo.ScHqSysHqBillTwoVo;
import com.ruoyi.statisticalCenter.service.ScHqSysHqBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sc/hqSysHqBill")
@Api(tags = "统计中心-总部系统明细账-总部账单")
public class ScHqSysHqBillController {
    @Autowired
    private ScHqSysHqBillService scHqSysHqBillService;
    @Autowired
    private TableService tableService;


    @ApiOperation("汇总1")
    @PostMapping("/collectOne")
    public R collectOne(@RequestBody ScHqSysHqBillOneVo vo){
        if (vo != null){
            String startTime = vo.getStartTime().replace("-", "");
            String endTime = vo.getEndTime().replace("-", "");
            vo.setStartTime(startTime);
            vo.setEndTime(endTime);
        }
        List<ScHqSysHqBillOne> sheets = scHqSysHqBillService.collect(vo);
        if (sheets == null || sheets.size() == 0){
            return R.fail("暂无数据");
        }else {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("list",PageInfo.info(sheets));
            jsonObject.put("fields",scHqSysHqBillService.initTable());
            return R.ok(jsonObject);
        }
    }
    @ApiOperation("汇总2")
    @PostMapping("/collectTwo")
    public R collectTwo(@RequestBody ScHqSysHqBillTwoVo vo){

        List<ScHqSysHqBillTwo> sheets = scHqSysHqBillService.collect(vo);
        if (sheets == null || sheets.size() == 0){
            return R.fail("暂无数据");
        }else {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("list",PageInfo.info(sheets));
            jsonObject.put("fields",scHqSysHqBillService.initTable2());
            return R.ok(jsonObject);
        }
    }
}
